`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    12:14:13 02/23/2014 
// Design Name: 
// Module Name:    vga 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module vga(	clk_old, 
				enable1,
				enable2, 
				enable3, 
				red,
				green,
				blue,
				HS,
				VS,
				a,
				b,
				c,
				d,
				lives,
				start,
				X1,
				Y1,
				X2,
				Y2,
				X3,
				Y3,
				X4,
				Y4,
				stop);
				
				input stop;
				input start;
				input wire clk_old;
				input enable1;											//if its enable 1 than X cordinate=100,Y=85;
				input enable2;											//enable2=1 than X=135,Y=85
				input enable3;											// enable3=1 than X=170, Y=85
				input [10:0] X1,Y1,X2,Y2,X3,Y3,X4,Y4;
				input  [3:0] a,b,c,d;
				input [3:0] lives;
			   output reg [2:0] red;
				output reg [2:0] green; 
				output  reg [1:0] blue;
				output HS;
				output VS;
				wire [10:0] hcounter1,hcounter2,hcounter3;
				assign hcounter1=hcounter-50;
				assign hcounter2=hcounter-100;
				assign hcounter3=hcounter-150;
				
				wire vgadisp1,vgadisp2,vgadisp3,vgadisp4;
				wire vgadisp5,vgadisp6,vgadisp7,vgadisp8,displives;
				wire [10:0] hcounter;
				wire [10:0] vcounter;
				wire blank;
				wire [14:0] addra;
				wire [7:0] data;
				wire [14:0] addrb;
				wire [7:0] data1;
				//input collision;
				

	slowclk1 Q1( clk_old, pixel_clk);
	vga_controller Q2(pixel_clk, HS,VS,hcounter,vcounter,blank); 
	//cordinate_select Q3(enable1,enable2,enable3,X,Y); //selects which (X,Y) pair is to be passed 
   
	vga_controller_640_60 h0(	vgadisp5,
										vgadisp6,
										vgadisp7,
										vgadisp8,
										enable1,
										enable2,
										enable3,
										X1,
										Y1,
										X2,
										Y2,
										X3,
										Y3,
										X4,
										Y4,
										hcounter, 
										vcounter,
										blank);
										
	addrcalc v1(start,hcounter, vcounter,blank,addra);
	startpage v2(pixel_clk,addra,data);
	addresscal v3(stop,hcounter,vcounter,blank,addrb);
	t_loserpage v4(pixel_clk,addrb,data1);

scoredisplay h1(a,vgadisp1,hcounter, vcounter,blank);
	scoredisplay h2(b,vgadisp2,hcounter1, vcounter,blank);
	
	scoredisplay h3(c,vgadisp3,hcounter2, vcounter,blank);

	
	scoredisplay h4(d,vgadisp4,hcounter3, vcounter,blank);
	vga_controller_640_60_1 h5(lives,displives,hcounter, vcounter,blank);	

always@(posedge pixel_clk) begin

if( start && ~blank) begin
	{red,green,blue}=data;
end
	else if( stop && ~blank) begin
		{red,green,blue}=data1;
	end
	else if(vgadisp1 || vgadisp2 || vgadisp3 || vgadisp4) begin
		red=3'b011;
		green=3'b110;
		blue=2'b10;
		end
	else if( displives) begin
			red=3'b111;
			green=3'b010;
			blue=2'b00;
			end

else if(vgadisp8) begin
red=3'b111;
green=3'b011;
blue=2'b01;
end

else if(vgadisp6 ||vgadisp7 || vgadisp5) begin 
red=3'b100;
green=3'b001;
blue=2'b01;
end




/*else if(collision==1) begin
vgadisp1=0;
vgadisp2=0;
vgadisp3=0;
vgadisp4=0;
vgadisp5=0;
vgadisp6=0;
vgadisp7=0;
vgadisp8=0;
displives=0;
end*/

else begin
red=3'b000;
green=3'b000;
blue=2'b00;
end
end
endmodule

